using System.Diagnostics;
using Blog.web.Models;
using Microsoft.AspNetCore.Mvc;

namespace Blog.web.Controllers;

public class BlogController:Controller
{
   
     public IActionResult Index(int id)
     {
          return Content(id.ToString());
     }

     public IActionResult Index_2(string id)
     {
        return Content(id);
     }

     public IActionResult Index_3(string name)
     {
        return Content(name);
     }
      [HttpPost]
     public IActionResult Create([FromBody] BlogCreateDao pblogCreateDto)
     {
        return Content(pblogCreateDto.Title);

     }
      [HttpPost]
      public IActionResult Create_1([FromBody] Products pblogCreateDto)
     {
        return Content(pblogCreateDto.Name);

     }

      [HttpPost]
        public IActionResult Create_2([FromBody] Students studentCreateDto)
     {

        return Content("姓名："+studentCreateDto.StudentName);

     }


   //   重定向

   public IActionResult Abc()
   {
      return RedirectToAction("Hhh");
   }
   
   public IActionResult Hhh()
   {
      return View();
   }

   
   // 渲染简单数据到页面

   public IActionResult Students()
   {
      string name="丸子";
      return Content(name);
      
   }

   // 渲染复杂数据到页面
        public IActionResult Students_2(){
        var obj=new Students
        {
            StudentName="小猪",
            Sex="男",
            Age=18
        };
        return Content($"姓名：{obj.StudentName},性别：{obj.Sex},年龄：{obj.Age}");
        
    }

   // 渲染集合数据到页面

   public IActionResult Students_3()
   {
      var stu =new List<BlogCreateDao>
      {
          new BlogCreateDao {Title="黑旋风",Author="男",Content="85"},
          new BlogCreateDao {Title="白旋风",Author="女",Content="86"},
          new BlogCreateDao {Title="灰旋风",Author="中性",Content="87"}
      };
      var num="      ";
      foreach (var item in stu)
      {
         num+=$"姓名：{item.Title}、性别{item.Author}、年龄{item.Content}           ";
      }
      return Content(num);
   }
}
